﻿package domino 
{
	/**
	 * ...
	 * @author ...
	 */
	import flash.media.Sound;
	import flash.media.SoundChannel;
	import flash.media.SoundTransform;

	public class sounds
	{
	    [Embed(source="sounds/click_button.mp3" )]
           public var click_button:Class;
		[Embed(source="sounds/click_rectangle.mp3")]
           public var click_rectangle:Class;
		[Embed(source="sounds/click_circle.mp3")]
           public var click_circle:Class;	
		[Embed(source="sounds/complete_level.mp3")]
           public var complete_level:Class;	
		[Embed(source="sounds/fail_level.mp3")]
           public var fail_level:Class;	
		[Embed(source="sounds/main_loop.mp3")]
           public var main_loop:Class;	
		[Embed(source="sounds/take_star.mp3")]
           public var take_star:Class;	  
		   
		   private var soundTr:SoundTransform = new SoundTransform(0, 4);
		   private var button:Sound ;
	       private var rectangle:Sound ;
	       private var circle:Sound ;
		   private var fail:Sound ;
		   private var complete:Sound ;
		   private var loop:Sound;
		   private var star:Sound;
		   private var Chanels:Array = [];
		   private var SoundCh:SoundChannel= new SoundChannel();
		   public var sound_inited:Boolean = true;
		   public function sounds():void {
			button = new click_button();
			rectangle = new click_rectangle();
			circle = new click_button();
			complete = new complete_level();
			fail = new fail_level();
			loop = new main_loop();
            star = new take_star(); 
		//	initSoundsChannels();
		   }//end
		   
		   private function initSoundsChannels():void
		   {
			   for (var i:int;i < 6;i++ ){
			    Chanels.push(new SoundChannel());
			    Chanels[i].soundTransform = soundTr;
				}
		   }
		   
		   public function PlaySound(str:String):Boolean {
			   if (sound_inited == false){
			    //SoundCh = new SoundChannel();
				trace("sound del");
			    return false;
		   }
				switch(str) {
				   case "button":
				    button.play();
				   break;
				   
				   case "rectangle":
				    button.play();
				   break;
				   
				   case "circle":
				    button.play();
				   break;
				   
				   case "complete":
				    complete.play()
				   break;
					
				   case "fail":
				    fail.play()
				   break;
					
				   case "star":
				    star.play()
				   break;
				   
				   case "loop":
				    SoundCh=loop.play(0,999);
				   break;
					
					case "start":
		             SoundCh = loop.play(0,999);
				    break;
					
				   case "stop":
					sound_inited = false;
					SoundCh.stop();
					break;
					
					
				   
				   }
				   return true;
			}//end
	}

}